<template>
  <div class="app-container">
    <el-dialog title="选择跳转文章" width="70%" :close-on-click-modal="false" :visible.sync="visible" append-to-body>
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="72px">
        <el-form-item label="文章标题" prop="title"><el-input v-model="queryParams.title" placeholder="请输入标题" clearable @keyup.enter.native="search" /></el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" border :data="contentList" ref="table" @select="select">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="文章标题" align="left" prop="title" />
        <el-table-column label="文章类型" align="center" prop="author" width="190" />
      </el-table>
      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ok()">确 定</el-button>
        <el-button @click="visible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { listContent, getContent, delContent, addContent, updateContent, exportContent, auditContent, endAuditContent, releaseContent } from '@/api/management/content';
export default {
  data() {
    return {
      loading: true,
      visible: false,
      total: 0,
      contentList: [],
      serviceInfoOptions: [],
      form: {},
      queryParams: {
        title: null,
        pageNum: 1,
        pageSize: 10,
        releaseFlag: 1,
        orderByColumn: 'createTime', //排序字段
        isAsc: 'desc' //排序方式
      }
    };
  },
  created() {},
  methods: {
    init() {
      this.visible = true;
      this.getList();
      this.getDicts('service_info').then(response => {
        this.serviceInfoOptions = response.data;
      });
    },
    /** 查询内容管理列表 */
    getList() {
      this.loading = true;
      listContent(this.queryParams).then(response => {
        this.loading = false;
        this.contentList = response.rows;
        this.total = response.total;
      });
    },
    //只允许单选
    select(selection, row) {
      this.form = row;
      if (selection.length > 1) {
        let del_row = selection.shift();
        this.$refs.table.toggleRowSelection(del_row, false);
      }
    },
    // 信息类型字典翻译
    serviceInfoFormat(row, column) {
      return this.selectDictLabel(this.serviceInfoOptions, row.serviceInfo);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    ok() {
      this.$emit('list', this.form);
      this.visible = false;
    }
  }
};
</script>
